import type { Recordable } from '@vben/types';

import { requestClient } from '#/api/request';

export namespace SystemDeptApi {
  export interface SystemDept {
    [key: string]: any;
    children?: SystemDept[];
    id: string;
    name: string;
    remark?: string;
    status: 0 | 1;
  }
}

/**
 * 获取部门列表数据
 */
const getDeptList = (params?: Recordable<any>): Promise<Array<SystemDeptApi.SystemDept>> => {
  return requestClient.get('/system/dept/', { params });
};

/**
 * 创建部门
 * @param data 部门数据
 */
const createDept = (
  data: Omit<SystemDeptApi.SystemDept, 'children' | 'id'>,
): Promise<SystemDeptApi.SystemDept> => {
  return requestClient.post('/system/dept/', data);
};

/**
 * 更新部门
 *
 * @param id 部门 ID
 * @param data 部门数据
 */
const updateDept = (
  id: string,
  data: Omit<SystemDeptApi.SystemDept, 'children' | 'id'>,
): Promise<SystemDeptApi.SystemDept> => {
  return requestClient.put(`/system/dept/${id}/`, data);
};

/**
 * 删除部门
 * @param id 部门 ID
 */
const deleteDept = (id: string): Promise<any> => {
  return requestClient.delete(`/system/dept/${id}/`);
};

/**
 * 查询tree
 */
const treeDept = (): Promise<any> => {
  return requestClient.get(`/system/dept/tree/`);
};

export { createDept, deleteDept, getDeptList, treeDept, updateDept };
